package org.jhotdraw.samples.phototemplate;

import com.itextpdf.text.PageSize;
import com.itextpdf.text.Rectangle;

/**
 *
 * @author Eliazar
 */
public class SizeDialogPDF extends javax.swing.JDialog {

    private Rectangle[] sizes;
    private Rectangle selectedSize;

    /**
     * Creates new form SizeDialogPDF
     */
    public SizeDialogPDF(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        sizes = new Rectangle[]{PageSize.A0, PageSize.A1, PageSize.A2, PageSize.A3, PageSize.A4, PageSize.B0, PageSize.B1, PageSize.B2, PageSize.B3, PageSize.B4, PageSize.A4_LANDSCAPE};
        selectedSize = sizes[4];
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        rdPortrait = new javax.swing.JRadioButton();
        rdLandscape = new javax.swing.JRadioButton();
        jButton1 = new javax.swing.JButton();
        cmbSizes = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Tamanho para impressão em pdf");
        setMaximumSize(new java.awt.Dimension(314, 122));
        setMinimumSize(new java.awt.Dimension(314, 122));

        jLabel1.setText("Tamanho do papel:");

        jLabel2.setText("Orientação:");

        buttonGroup1.add(rdPortrait);
        rdPortrait.setSelected(true);
        rdPortrait.setText("Retrato");
        rdPortrait.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                orientationRadios(evt);
            }
        });

        buttonGroup1.add(rdLandscape);
        rdLandscape.setText("Paisagem");
        rdLandscape.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                orientationRadios(evt);
            }
        });

        jButton1.setText("Ok");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        cmbSizes.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "A0                  841 x 1189   mm", "A1                  594 x 841     mm", "A2                  420 x 594     mm", "A3                  297 x 420     mm", "A4                  210 x 297     mm", "B0                  1000 x 1414 mm", "B1                  707 x 1000   mm", "B2                  500 x 707     mm", "B3                  353 x 500     mm", "B4                  250 x 353     mm" }));
        cmbSizes.setSelectedIndex(4);
        cmbSizes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                changeSize(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(rdPortrait)
                        .addGap(18, 18, 18)
                        .addComponent(rdLandscape))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jLabel1)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(cmbSizes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(37, 37, 37))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(cmbSizes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rdPortrait)
                    .addComponent(rdLandscape))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton1)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void changeSize(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_changeSize
        selectedSize = sizes[cmbSizes.getSelectedIndex()];
        if(cmbSizes.getSelectedIndex() == 4) {
            rdLandscape.setEnabled(true);
            rdPortrait.setEnabled(true);
        }else {
            rdLandscape.setEnabled(false);
            rdPortrait.setEnabled(false);
            rdPortrait.setSelected(false);
        }
        

    }//GEN-LAST:event_changeSize

    private void orientationRadios(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_orientationRadios
        if(rdLandscape.isSelected()) {
            selectedSize = sizes[10];
        }else {
            selectedSize = sizes[4];
        }
    }//GEN-LAST:event_orientationRadios

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        setVisible(false);
    }//GEN-LAST:event_jButton1ActionPerformed

    public Rectangle getSelectedSize() {
        return selectedSize;
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(SizeDialogPDF.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(SizeDialogPDF.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(SizeDialogPDF.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(SizeDialogPDF.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                SizeDialogPDF dialog = new SizeDialogPDF(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JComboBox cmbSizes;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JRadioButton rdLandscape;
    private javax.swing.JRadioButton rdPortrait;
    // End of variables declaration//GEN-END:variables
}
